//
//  FCManageCoinsVC.m
//  FundChain
//
//  Created by 肖浩然的mac on 2018/2/27.
//  Copyright © 2018年 RUIXIN. All rights reserved.
//

#import "FCManageCoinsVC.h"
#import "FCManageCoinsCell.h"
#import "FCManageCoinsReusableView.h"
@interface FCManageCoinsVC ()<UICollectionViewDelegate,UICollectionViewDataSource>{
    UIView     *_viewNav;
}

/* collectionView */
@property (strong, nonatomic) UICollectionView *collectionView;
/* 组头title */
@property (strong, nonatomic) NSArray  *titleArr;
/* 钱包title */
@property (strong, nonatomic) NSArray  *walletTitleArr;
/* 所有钱包 */
@property (strong, nonatomic) NSMutableArray  *walletArr;
/* 所有移除的钱包 */
@property (strong, nonatomic) NSMutableArray  *deleteWalletArr;
/* 钱包头像*/
@property (strong, nonatomic) NSArray  *walletIconArr;

/* <#Annotation#> */
@property (strong, nonatomic) NSMutableArray *arrMut;

@property (strong, nonatomic) NSMutableArray *deleteArrMut;

@property (strong, nonatomic) FCWalletsModel *walletModel1;
@property (strong, nonatomic) FCWalletsModel *walletModel2;
@property (strong, nonatomic) FCWalletsModel *walletModel3;
@property (strong, nonatomic) FCWalletsModel *walletModel4;
@property (strong, nonatomic) FCWalletsModel *walletModel5;

@property (strong, nonatomic) FCWalletsModel *walletModeld1;
@property (strong, nonatomic) FCWalletsModel *walletModeld2;
@property (strong, nonatomic) FCWalletsModel *walletModeld3;
@property (strong, nonatomic) FCWalletsModel *walletModeld4;
@property (strong, nonatomic) FCWalletsModel *walletModeld5;

@property (copy, nonatomic) NSString *cchStatus;

/* 记录左边更改等值货币的 */
@property (strong, nonatomic) FCCurrentResultModel *currentResultModel;
@end

@implementation FCManageCoinsVC
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
     [self getCCHStatus];
    FCCCHStatusModel *model = [FCLocalUserHelper getCCHstatusModel];
    self.cchStatus = model.statusStr;
    
    [FCLocalUserHelper saveIsMainVC:@"0"];
    _titleArr = @[Localized(@"您可以点击以下货币添加到您的钱包中。"),Localized(@"您可以点击以下货币从您的钱包中刪除。")];
    //自定义导航栏
    [self setNav];
    //设置UI
    [self setupUI];
    [self loadData];
    [self addImageArr];
    [self addTitleArr];
    
    
    
}
-(void)addImageArr{
    
    self.walletIconArr = @[@"btc_50pt",@"ltc_50pt",@"bch_50pt",@"cch_50pt",@"zec_50pt"];
}
-(void)addTitleArr{
    
    self.walletTitleArr = @[Localized(@"比特币"),Localized(@"莱特币"),Localized(@"比特币现金"),Localized(@"加密现金币"),Localized(@"零币")];
}
#pragma mark-UIcollectionView&UICollectionViewDataSource

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    if (kind == UICollectionElementKindSectionHeader) {
        
        FCManageCoinsReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"manageCoinsHeaderView" forIndexPath:indexPath];
        
        
        headerView.titleLabel.text = _titleArr[indexPath.section];
        
        return headerView;
    }
    
    
    return nil;
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 2;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    if (section == 0) {
        return self.deleteWalletArr.count;
    }else if (section == 1){
        
        return self.walletArr.count;
    }
    return 0;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (SCREEN_WIDTH == 320) {
        
        return CGSizeMake(320*KScreenWidthScale750, 300*KScreenHeightScale1334);
    }else{
    return CGSizeMake(320*KScreenWidthScale750, 292*KScreenHeightScale1334);
    }
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    FCManageCoinsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"manageCoinsCollectionViewCell" forIndexPath:indexPath];
    if (indexPath.section == 1) {
        [cell.imageView setImage:[UIImage imageNamed:@"delete_manage"] forState:UIControlStateNormal];
        FCWalletsModel *model = self.walletArr[indexPath.row];
        FCBalanceModel *balanceModel = [FCLocalUserHelper getFMDBBalanceData:model.walletId];
       
        switch ([model.walletId integerValue]) {
            case 1001:
            {
                cell.iconImageView.image  = [UIImage imageNamed:self.walletIconArr[0]];
                cell.nickNameLabel.text = self.walletTitleArr[0];
                cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f USD",[balanceModel.balance floatValue]];
                 FCExchangeRatesModel *model = [FCLocalUserHelper getFMDBExchangeRatesModel:@"1001"];
                if (model) {
                    float balance = [balanceModel.balance floatValue];
                    float result = balance*[model.price floatValue];
                     cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f %@",result,model.currentName];
                    
                }
            }
                break;
            case 1005:
            {
                cell.iconImageView.image  = [UIImage imageNamed:self.walletIconArr[1]];
                cell.nickNameLabel.text = self.walletTitleArr[1];
                cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f USD",[balanceModel.balance floatValue]];
                FCExchangeRatesModel *model = [FCLocalUserHelper getFMDBExchangeRatesModel:@"1005"];
                if (model) {
                    float balance = [balanceModel.balance floatValue];
                    float result = balance*[model.price floatValue];
                   cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f %@",result,model.currentName];
                    
                }
            }
                break;
            case 1006:
            {
                cell.iconImageView.image  = [UIImage imageNamed:self.walletIconArr[2]];
                cell.nickNameLabel.text = self.walletTitleArr[2];
                cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f USD",[balanceModel.balance floatValue]];
                FCExchangeRatesModel *model = [FCLocalUserHelper getFMDBExchangeRatesModel:@"1006"];
                if (model) {
                    float balance = [balanceModel.balance floatValue];
                    float result = balance*[model.price floatValue];
                    cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f %@",result,model.currentName];
                    
                }
            }
                break;
            case 1009:
            {
                cell.iconImageView.image  = [UIImage imageNamed:self.walletIconArr[3]];
                cell.nickNameLabel.text = self.walletTitleArr[3];
                 cell.distanceLabel.text = [NSString stringWithFormat:@"=%.2f CCH",[balanceModel.balance floatValue]];
                FCExchangeRatesModel *model = [FCLocalUserHelper getFMDBExchangeRatesModel:@"1009"];
                if (model) {
                    float balance = [balanceModel.balance floatValue];
                    float result = balance*[model.price floatValue];
                  cell.distanceLabel.text = [NSString stringWithFormat:@"=%.2f %@",result,model.currentName];
                    
                }
            }
                break;
            case 1010:
            {
                cell.iconImageView.image  = [UIImage imageNamed:self.walletIconArr[4]];
                cell.nickNameLabel.text = self.walletTitleArr[4];
                 cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f USD",[balanceModel.balance floatValue]];
                FCExchangeRatesModel *model = [FCLocalUserHelper getFMDBExchangeRatesModel:@"1010"];
                if (model) {
                    float balance = [balanceModel.balance floatValue];
                    float result = balance*[model.price floatValue];
                   cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f %@",result,model.currentName];
                    
                }
            }
                break;
            default:
                break;
               
        }
    }else if (indexPath.section == 0){
        
        [cell.imageView setImage:[UIImage imageNamed:@"choose_manage"] forState:UIControlStateNormal];
        FCWalletsModel *model = self.deleteWalletArr[indexPath.row];
        FCBalanceModel *balanceModel = [FCLocalUserHelper getFMDBBalanceData:model.walletId];
        
        switch ([model.walletId integerValue]) {
            case 1001:
            {
                cell.iconImageView.image  = [UIImage imageNamed:self.walletIconArr[0]];
                cell.nickNameLabel.text = self.walletTitleArr[0];
                cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f USD",[balanceModel.balance floatValue]];
                FCExchangeRatesModel *model = [FCLocalUserHelper getFMDBExchangeRatesModel:@"1001"];
                if (model) {
                    float balance = [balanceModel.balance floatValue];
                    float result = balance*[model.price floatValue];
                    cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f %@",result,model.currentName];
                    
                }
            }
                break;
            case 1005:
            {
                cell.iconImageView.image  = [UIImage imageNamed:self.walletIconArr[1]];
                cell.nickNameLabel.text = self.walletTitleArr[1];
               cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f USD",[balanceModel.balance floatValue]];
                FCExchangeRatesModel *model = [FCLocalUserHelper getFMDBExchangeRatesModel:@"1005"];
                if (model) {
                    float balance = [balanceModel.balance floatValue];
                    float result = balance*[model.price floatValue];
                    cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f %@",result,model.currentName];
                    
                }
            }
                break;
            case 1006:
            {
                cell.iconImageView.image  = [UIImage imageNamed:self.walletIconArr[2]];
                cell.nickNameLabel.text = self.walletTitleArr[2];
               cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f USD",[balanceModel.balance floatValue]];
                FCExchangeRatesModel *model = [FCLocalUserHelper getFMDBExchangeRatesModel:@"1006"];
                if (model) {
                    float balance = [balanceModel.balance floatValue];
                    float result = balance*[model.price floatValue];
                    cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f %@",result,model.currentName];
                    
                }
            }
                break;
            case 1009:
            {
                cell.iconImageView.image  = [UIImage imageNamed:self.walletIconArr[3]];
                cell.nickNameLabel.text = self.walletTitleArr[3];
               cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f CCH",[balanceModel.balance floatValue]];
                FCExchangeRatesModel *model = [FCLocalUserHelper getFMDBExchangeRatesModel:@"1009"];
                if (model) {
                    float balance = [balanceModel.balance floatValue];
                    float result = balance*[model.price floatValue];
                    cell.distanceLabel.text = [NSString stringWithFormat:@"=%.2f %@",result,model.currentName];
                    
                }
            }
                break;
            case 1010:
            {
                cell.iconImageView.image  = [UIImage imageNamed:self.walletIconArr[4]];
                cell.nickNameLabel.text = self.walletTitleArr[4];
                cell.distanceLabel.text = [NSString stringWithFormat:@"≈%.2f USD",[balanceModel.balance floatValue]];
                FCExchangeRatesModel *model = [FCLocalUserHelper getFMDBExchangeRatesModel:@"1010"];
                if (model) {
                    float balance = [balanceModel.balance floatValue];
                    float result = balance*[model.price floatValue];
                    cell.distanceLabel.text = [NSString stringWithFormat:@"=%.2f %@",result,model.currentName];
                    
                }
            }
                break;
            default:
                break;
                
        }
        
    }
    
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    //    FCAddCoinsCell *item = (FCAddCoinsCell*)[collectionView cellForItemAtIndexPath:indexPath];
    if (indexPath.section == 0) {
        
        FCWalletsModel *model = self.deleteWalletArr[indexPath.row];
        NSLog(@"第0组点击了%@=",model.walletId);
        //添加货币
        [self addWallet:model.walletId];
    }
    if (indexPath.section == 1) {
        FCWalletsModel *model = self.walletArr[indexPath.row];
        NSLog(@"第一组点击了%@=",model.walletId);
        [self deleteWallet:model.walletId];
    }
}

#pragma mark-设置UI
-(void)setupUI{
//    UIView *hintView = [UIView new];
//    [self.view addSubview:hintView];
//    [hintView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(_viewNav.mas_bottom);
//        make.left.right.mas_equalTo(0);
//        make.height.mas_equalTo(100*KScreenHeightScale1334);
//    }];
//    //提示语
//    UILabel *hintLabel = [UILabel new];
//    [hintView addSubview:hintLabel];
//    [hintLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(30*KScreenWidthScale750);
//        make.centerY.mas_equalTo(0);
//    }];
//    hintLabel.font = Kfont(28);
//    hintLabel.textColor = kOrderColor;
//    hintLabel.text = @"You can touch following coins to add them in wallet";
    //瀑布流
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    [layout setScrollDirection:(UICollectionViewScrollDirectionVertical)];
    //    layout.minimumLineSpacing = 10=;// 水平方向的间距
    //    layout.minimumInteritemSpacing = 10;
    layout.sectionInset = UIEdgeInsetsMake(0, 15, 10, 15);
    layout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH, 100*KScreenHeightScale1334);
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
    self.collectionView = collectionView;
    [self.view addSubview:collectionView];
    [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_viewNav.mas_bottom);
        make.left.right.bottom.mas_equalTo(0);
    }];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    collectionView.backgroundColor = [UIColor clearColor];
    //设置可以多选
    collectionView.allowsMultipleSelection=YES;
    //注册组头
    
    [collectionView registerClass:[FCManageCoinsReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"manageCoinsHeaderView"];
    //注册cell
    [collectionView registerClass:[FCManageCoinsCell class] forCellWithReuseIdentifier:@"manageCoinsCollectionViewCell"];
   
}
#pragma mark-自定义导航栏
-(void)setNav{
    
    _viewNav =[UIView new];
    [self.view addSubview:_viewNav];
    [_viewNav mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0, *)) {
            if (iPhoneX) {
                
                make.left.right.top.mas_equalTo(self.view.safeAreaInsets);
                make.height.mas_equalTo(88);
            }else{
                make.left.right.mas_equalTo(0);
                make.height.mas_equalTo(64);
                make.top.mas_equalTo(0);
            }
        }else{
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(64);
            make.top.mas_equalTo(0);
        }
        
    }];
    _viewNav.backgroundColor = kRedOrangeColor;
    
    UIButton *leftBtn = [UIButton new];
    [self.view addSubview:leftBtn];
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15*KScreenWidthScale750);
        make.centerY.mas_equalTo(_viewNav.mas_centerY).offset(8);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    [leftBtn setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
    
    [leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    //返回
    UILabel *backLabel = [UILabel new];
    
    [_viewNav addSubview:backLabel];
    [backLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_viewNav);
        make.centerY.mas_equalTo(_viewNav.mas_centerY).offset(8);
    }];
    backLabel.text = Localized(@"管理加密货币");
    backLabel.textColor = [UIColor whiteColor];
    backLabel.font = KOverstrikingfont(36);
    
    //事件
    [leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
}

#pragma mark-返回
-(void)leftBtnClick{
    //发送左边刷新钱包货币个数的通知
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    
        [[NSNotificationCenter defaultCenter]postNotificationName:@"leftChangeReloadWallet" object:nil];
        [self.navigationController popViewControllerAnimated:YES];
//    });
    
}
#pragma mark-添加钱包货币
-(void)addWallet:(NSString*)walletId{
    
    [self showChrysanthemumAlert:nil];
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
    NSArray *arrM =[FCLocalUserHelper getTimeAndSign];
    NSString *signStr = [NSString stringWithFormat:@"%@",arrM[1]];
    NSString *timeStr = [NSString stringWithFormat:@"%@",arrM[0]];
    [dict setObject:[FCLocalUserHelper sha1:signStr] forKey:@"sign"];
    [dict setObject:timeStr forKey:@"time"];
    [dict setObject:[FCLocalUserHelper getXidStr] forKey:@"XID"];
    [dict setObject:walletId forKey:@"walletId"];
    NSString *url = Add_wallet_type_URL;
    __weak __typeof(self)wself = self;
    [FCSharedNetworkTool POSTWithURLString:url parameters:dict success:^(id responseObject) {
        if (responseObject) {
            if ([responseObject[@"code"] integerValue] == 200) {
                [self hideProgress];
                NSLog(@"%@",responseObject);
//                 [self showAlert:Localized(@"添加钱包成功")];
                //获取所有钱包信息
                [wself loadData];
            }else if ([responseObject[@"code"] integerValue] == 400){
                [self hideProgress];
                [self showAlert:Localized(@"添加钱包失败")];
            }
            
            
        }
        
        
        
    } faile:^(NSError *error) {
        if (error) {
            NSLog(@"%@",error);
        }
        [self hideProgress];
    }];
    
    
}
#pragma mark-删除钱包
-(void)deleteWallet:(NSString*)walletId{
    
    // 删除货币
    if (_walletArr.count <2) {
        [self showAlert:Localized(@"至少选择一个货币")];
        return;
    }
    [self showChrysanthemumAlert:nil];
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
    NSArray *signArr = [FCLocalUserHelper getTimeAndSign];
    NSString *signStr = [NSString stringWithFormat:@"%@",signArr[1]];
    NSString *timeStr = [NSString stringWithFormat:@"%@",signArr[0]];
    [dict setObject:[FCLocalUserHelper sha1:signStr] forKey:@"sign"];
    [dict setObject:timeStr forKey:@"time"];
    [dict setObject:[FCLocalUserHelper getXidStr] forKey:@"XID"];
    [dict setObject:walletId forKey:@"walletId"];
    NSString *url = Remove_wallet_type_URL;
    
    __weak __typeof(self)wself = self;
    [FCSharedNetworkTool POSTWithURLString:url parameters:dict success:^(id responseObject) {
        
        if (responseObject) {
            NSLog(@"%@",responseObject);
            if ([responseObject[@"code"] integerValue] == 200) {
                [self hideProgress];
//                [self showAlert:Localized(@"移除钱包成功")];
             
                //获取所有钱包信息
                [wself loadData];
               
                
            }else if ([responseObject[@"code"] integerValue] == 400){
                [self hideProgress];
                [self showAlert:Localized(@"移除钱包失败")];
            }
        }
        
    } faile:^(NSError *error) {
        if (error) {
            NSLog(@"%@",error);
        }
         [self hideProgress];
    }];
    
    
}
#pragma mark-加载数据源
-(void)loadData{
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
    NSArray *signArr = [FCLocalUserHelper getTimeAndSign];
    NSString *signStr = [NSString stringWithFormat:@"%@",signArr[1]];
    NSString *timeStr = [NSString stringWithFormat:@"%@",signArr[0]];
    [dict setObject:[FCLocalUserHelper sha1:signStr] forKey:@"sign"];
    [dict setObject:timeStr forKey:@"time"];
    [dict setObject:[FCLocalUserHelper getXidStr] forKey:@"XID"];
    NSString *url = Get_load_wallets_URL;
    __weak __typeof(self)wself = self;
    [FCSharedNetworkTool POSTWithURLString:url parameters:dict success:^(id responseObject) {
        if (responseObject) {
            NSLog(@"%@",responseObject);
            if ([responseObject[@"code"] integerValue] == 200) {
                NSArray *arr = responseObject[@"result"];
                
                if (self.walletArr.count>0) {
                    [self.walletArr removeAllObjects];
                }
                if (self.deleteWalletArr.count>0) {
                    [self.deleteWalletArr removeAllObjects];
                }
                [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    FCWalletsModel *model = [FCWalletsModel mj_objectWithKeyValues:obj];
                    NSString *xidStr = [FCLocalUserHelper getXidStr];
                    model.XID = xidStr;
                    
                        if ([model.choice isEqualToString:@"1"]) {
                            if ([self.cchStatus isEqualToString:@"0"]) {
                                
                                if ([model.walletId isEqualToString:@"1001"]) {
                                    self.walletModel2 = model;
                                    [wself.arrMut addObject:self.walletModel2];
                                }
                                if ([model.walletId isEqualToString:@"1006"]) {
                                    self.walletModel3 = model;
                                    [wself.arrMut addObject:self.walletModel3];
                                }
                                if ([model.walletId isEqualToString:@"1005"]) {
                                    self.walletModel4 = model;
                                    [wself.arrMut addObject:self.walletModel4];
                                }
                                if ([model.walletId isEqualToString:@"1010"]) {
                                    self.walletModel5 = model;
                                    [wself.arrMut addObject:self.walletModel5];
                                }
                                
                            }else{
                                if ([model.walletId isEqualToString:@"1009"]) {
                                    self.walletModel1 = model;
                                    [wself.arrMut addObject:self.walletModel1];
                                    
                                }
                                if ([model.walletId isEqualToString:@"1001"]) {
                                    self.walletModel2 = model;
                                    [wself.arrMut addObject:self.walletModel2];
                                }
                                if ([model.walletId isEqualToString:@"1006"]) {
                                    self.walletModel3 = model;
                                    [wself.arrMut addObject:self.walletModel3];
                                }
                                if ([model.walletId isEqualToString:@"1005"]) {
                                    self.walletModel4 = model;
                                    [wself.arrMut addObject:self.walletModel4];
                                }
                                if ([model.walletId isEqualToString:@"1010"]) {
                                    self.walletModel5 = model;
                                    [wself.arrMut addObject:self.walletModel5];
                                }
                                
                            }
                            
                            
                            
                        }else if([model.choice isEqualToString:@"0"]){
                            
                            if ([self.cchStatus isEqualToString:@"0"]) {
                                
                                if ([model.walletId isEqualToString:@"1001"]) {
                                    self.walletModeld2 = model;
                                    [wself.deleteArrMut addObject:self.walletModeld2];
                                }
                                if ([model.walletId isEqualToString:@"1006"]) {
                                    self.walletModeld3 = model;
                                    [wself.deleteArrMut addObject:self.walletModeld3];
                                }
                                if ([model.walletId isEqualToString:@"1005"]) {
                                    self.walletModeld4 = model;
                                    [wself.deleteArrMut addObject:self.walletModeld4];
                                }
                                if ([model.walletId isEqualToString:@"1010"]) {
                                    self.walletModeld5 = model;
                                    [wself.deleteArrMut addObject:self.walletModeld5];
                                }
                                
                            }else{
                                if ([model.walletId isEqualToString:@"1009"]) {
                                    self.walletModeld1 = model;
                                    [wself.deleteArrMut addObject:self.walletModeld1];
                                    
                                }
                                if ([model.walletId isEqualToString:@"1001"]) {
                                    self.walletModeld2 = model;
                                    [wself.deleteArrMut addObject:self.walletModeld2];
                                }
                                if ([model.walletId isEqualToString:@"1006"]) {
                                    self.walletModeld3 = model;
                                    [wself.deleteArrMut addObject:self.walletModeld3];
                                }
                                if ([model.walletId isEqualToString:@"1005"]) {
                                    self.walletModeld4 = model;
                                    [wself.deleteArrMut addObject:self.walletModeld4];
                                }
                                if ([model.walletId isEqualToString:@"1010"]) {
                                    self.walletModeld5 = model;
                                    [wself.deleteArrMut addObject:self.walletModeld5];
                                }
                            }
                            
                            
                        }
//                    }
                }];
                wself.arrMut = [wself getAnArrayWithArray:self.arrMut];
                wself.walletArr =  wself.arrMut;
                wself.deleteArrMut = [wself getAnArrayWithArray:self.deleteArrMut];
                wself.deleteWalletArr =  wself.deleteArrMut;
                [self.collectionView reloadData];
            }
            
        }
        
    } faile:^(NSError *error) {
        if (error ) {
            NSLog(@"%@",error);
        }
        
    }];
}
-(NSMutableArray *) getAnArrayWithArray:(NSMutableArray*)theArray
{
    NSMutableArray * mutableArray = [[NSMutableArray alloc]init];
    
    
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j<theArray.count; j++) {
            FCWalletsModel * modelj = theArray[j];
            if ([modelj.walletId isEqualToString:@"1009"] && i==0) {
                [mutableArray addObject:modelj];
                
            }
            if ([modelj.walletId isEqualToString:@"1001"] && i==1) {
                [mutableArray addObject:modelj];
            }
            if ([modelj.walletId isEqualToString:@"1006"] && i==2) {
                [mutableArray addObject:modelj];
            }
            if ([modelj.walletId isEqualToString:@"1005"] && i==3) {
                [mutableArray addObject:modelj];
            }
            if ([modelj.walletId isEqualToString:@"1010"] && i==4) {
                [mutableArray addObject:modelj];
            }
        }
    }
    return mutableArray;
}
-(void)getCCHStatus{
    
    NSString *url = @"https://app.fund-chain.io/Fundchain/index.php/Api/Base/is_show_coin_1_0";
    [FCSharedNetworkTool POSTWithURLString:url parameters:nil success:^(id responseObject) {
        if (responseObject) {
            if ([responseObject[@"code"] integerValue] == 200) {
                NSLog(@"CCH是%@",responseObject[@"result"][@"show"]);
                NSString *res = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"show"]];
                FCCCHStatusModel *model = [FCCCHStatusModel new];
                model.statusStr = res;
                [FCLocalUserHelper saveCCHStatus:model];
                
            }
        }
        
        
    } faile:^(NSError *error) {
        
        
    }];
}
-(NSMutableArray *)walletArr{
    if (!_walletArr) {
        _walletArr = [NSMutableArray new];
    }
    return _walletArr;
}
-(NSMutableArray *)deleteWalletArr{
    if (!_deleteWalletArr) {
        _deleteWalletArr = [NSMutableArray new];
    }
    return _deleteWalletArr;
}
-(NSMutableArray *)arrMut{
    if (!_arrMut) {
        _arrMut = [NSMutableArray new];
    }
    return _arrMut;
}
-(NSMutableArray *)deleteArrMut{
    if (!_deleteArrMut) {
        _deleteArrMut = [NSMutableArray new];
    }
    return _deleteArrMut;
}
@end
